﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;


public partial class AnaSayfa : System.Web.UI.Page
{
    protected void Page_PreRender(object sender, EventArgs e)
    {
        DilDegistir();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.Cookies["dil"] == null)
            {
                HttpCookie dilCookie = new HttpCookie("dil");
                dilCookie.Value = "TR";
                dilCookie.Expires = DateTime.Now.AddMonths(6);
                Response.Cookies.Add(dilCookie);
            }

            Sessions.SiparisFiyati = null;
            DataAccess.GetLookUp();

            DilDegistir();
        }




        //if (Request.Cookies["AnonimUye"]==null && Sessions.UyeId==-1)
        //{
        //    HttpCookie AnonimUyeCookie = new HttpCookie("AnonimUye");
        //    AnonimUyeCookie.Values["AnonimUyeId"] = Guid.NewGuid().ToString();
        //    AnonimUyeCookie.Expires = DateTime.Now.AddMonths(1);
        //    Response.Cookies.Add(AnonimUyeCookie);
        //}

        //if (Request.Cookies["Sepet"] != null)
        //{
        //    HttpCookie SepetCookie = new HttpCookie("Sepet");
        //    SepetCookie.Expires = DateTime.Now.AddDays(-1);
        //    Response.Cookies.Add(SepetCookie);
        //}

    }

    protected void DilDegistir()
    {

        if (Cookies.Dil == "TR")
        {
            lblBayanCanta.Text = "BAYAN ÇANTA";
            lblErkekCanta.Text = "ERKEK ÇANTA";
            lblSectiklerimiz.Text = "Sizin İçin Seçtiklerimiz";
        }
        else
        {
            lblBayanCanta.Text = "WOMEN BAG";
            lblErkekCanta.Text = "MEN BAG";
            lblSectiklerimiz.Text = "Special For You";
        }
    }

    protected void btnHelper_Click(object sender, EventArgs e)
    {
        if (Sessions.UyeId > 0)
        {
            string sr = hidUrunId.Value;
            int UrunId = Convert.ToInt16(sr);

            int BegeniAdedi = DataAccess.UrunBegen(UrunId);
            Sessions.BegeniAdedi = BegeniAdedi;

            (this.Master as Skala).BegeniGuncelle(BegeniAdedi);
            listCanta.DataBind();
            //(this.Master as Skala).Guncelle((sender as HtmlAnchor).Attributes["Data"]);

        }
        else
            Response.Redirect(Page.GetRouteUrl("UyeGiris", new object { }));
    }

    public void Guncelle(Object sender, EventArgs e)
    {
        if (Sessions.UyeId > 0)
        {
            string sr = ((HtmlAnchor)sender).Attributes["Data"].ToString();
            int UrunId = Convert.ToInt16(sr);

            int BegeniAdedi = DataAccess.UrunBegen(UrunId);
            Sessions.BegeniAdedi = BegeniAdedi;

            (this.Master as Skala).BegeniGuncelle(BegeniAdedi);
        }
        else
            Response.Redirect(Page.GetRouteUrl("UyeGiris", new object { }));
    }


    protected void btnCantayaEkle_Click(object sender, EventArgs e)
    {
        if (Sessions.UyeId > 0)
        {
            string CantaDurumu = hidCantaDurumu.Value;
            string sr = hidUrunId.Value;
            int UrunId = Convert.ToInt16(sr);
            int SepetAdedi;

            if (CantaDurumu == "cantayaEkle")
            {
                DataRow drSepet = DataAccess.CantayaEkle(UrunId, 1);
                SepetAdedi = Convert.ToInt16(drSepet["SepetAdedi"]);
                Sessions.SepetAdedi = SepetAdedi;
            }
            else
            {
                SepetAdedi = DataAccess.CantadanCikar(UrunId);
                Sessions.SepetAdedi = SepetAdedi;
            }
            listCanta.DataBind();
            (this.Master as Skala).SepetAdediGuncelle(SepetAdedi);
        }
        else
            Response.Redirect(Page.GetRouteUrl("UyeGiris", new object { }));
    }

    protected void listCanta_ItemCommand(object sender, ListViewCommandEventArgs e)
    {
        if (e.CommandName == "begen")
        {
            int UrunId = int.Parse(e.CommandArgument.ToString());
            if (Sessions.UyeId > 0)
            {
                DataAccess.UrunBegen(UrunId);
                //listCanta.DataBind();
                //UpdatePanel1.Update();
            }
            else
                Response.Redirect(Page.GetRouteUrl("UyeGiris", new object { }));
        }
        //else if (e.CommandName=="cantada")
        //{

        //    int UrunId = int.Parse(e.CommandArgument.ToString());
        //    if (Sessions.UyeId > 0)
        //    {
        //        DataAccess.CantadanCikar(UrunId);
        //        listCanta.DataBind();
        //        UpdatePanel1.Update();
        //    }
        //    else
        //        Response.Redirect("Giris.aspx");
        //}
        //else if (e.CommandName=="cantayaEkle")
        //{
        //    int UrunId = int.Parse(e.CommandArgument.ToString());
        //    if (Sessions.UyeId > 0)
        //    {
        //        bool eklendiMi = DataAccess.CantayaEkle(UrunId, 1);
        //        if (eklendiMi)
        //        {
        //            //listCanta.DataSource = Urunler;
        //            listCanta.DataBind();
        //            UpdatePanel1.Update();
        //        }
        //    }
        //    else
        //        Response.Redirect("Giris.aspx");
        //}
    }
}